<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" id="text-box" size="20" value="Mozilla">
  <button onclick="selectText()">Select text</button>
</body>
<script>
  function selectText() {
    const input = document.getElementById('text-box');
    input.focus();
    // input.setSelectionRange(2, 5);
    input.setSelectionRange(0, 0);

  }
</script>

</html>